
function btn_click_start(){
	try { 
		 // WorkFlow_ExecuteSubmitSapForm();
	    } catch(error) { 
	}
	//设置备选列表
	//getUserOptional();
	//第三方系统表单数据校验
	var isVal = $("#isVal").val();
	//var isVal = "2";
	if(isVal == "1"){
		valitionForm();	
	}else{
		//岗位ID
		var postId=$("#postId").val();
		if(!isSubmit) {
			WorkFlow_FormSubmit();	
		}
	}	
}

//让提交按钮失效
function disableSubmit() {
	isSubmit = true;
	$("#flowSubmit").attr("disabled","disabled");
}

function valitionForm(){    
	//获取系统type
	var sysType = $("#sysType").val();
	//获取校验类型
	var valType = $("#valType").val();
	//获取流程实例ID
	var proInsId = $("#proInsId").val();
	//获取流程定义key
	var flowKey = $("#flowKey").val();
	//岗位ID
//	var postId=$("#postId").val();
//	
//	if(postID=="" || postId==null){
//		alert("岗位不能为空！");
//		return false;
//	}
	
	$.ajax({
	    type: 'POST',
	    async:false,
	    url: PATH+"/bpm/bpmsap/valitionForm" ,
	    data: {sysType:sysType,valType:valType,proInsId:proInsId,flowKey:flowKey},
	    dataType: "json",
	    success: function(result){
	    	if(result.messagetype == "2"){
				alert(result.message);
				$("#flowSubmit").attr("href","#");;
				return false;
			}else{
				//设置备选列表
				//getUserOptional();
				if(!isSubmit) {
					WorkFlow_FormSubmit();
				}
			}
	    }  
	});
}

function WorkFlow_ExecuteSubmitSapForm(){
	if(typeof(exec_obj)=='undefined'){  
        exec_obj = document.createElement('iframe');  
        exec_obj.name = 'tmp_frame';  
        exec_obj.src = 'http://sapecd-app.maoye.cn:8000/webform/refresh_webgui?sap-client=230';  
        exec_obj.style.display = 'none';  
        document.body.appendChild(exec_obj);  
    }else{  
        exec_obj.src = 'http://sapecd-app.maoye.cn:8000/webform/refresh_webgui?sap-client=230?' + Math.random();
    }  
}

function WorkFlow_FormSubmit(){
	disableSubmit();
	$("#form").attr("action", PATH+"/bpm/bpmsap/save");  	
 	$("#form").submit();
}

function initStartInfo(data){
	//初始化流程实例ID
	//if(data.proInsId){
	//	$("#proInsId").val(data.proInsId);	
	//}

	//初始化流程执行信息
	var bpm_flow_excute_type = data.bpm_flow_excute_type;
	if(bpm_flow_excute_type){
		$("#bpm_flow_excute_type").val(bpm_flow_excute_type);
	}
	$("#flowOpinions").attr("src",PATH+"/bpm/workflow/opinions?proInstID="); 
	initWorkFlowInfo(data);
	$(".workflow-opt-task-tr").css("display","none");
	var isopt = data.isopt;
	if(isopt){
		$("#is_work_flow_").val(true);
		if($(".att-show").find("input[name='soureBillID']")[0]){
			$($(".att-show").find("input[name='soureBillID']")[0]).val(proInsId);
		}
		initEditNodeInfo(data);
	}else{
		$(".att-show").css("display","none");
	}
	//初始化岗位信息
	if(data.userPosts){
		var userPosts = data.userPosts;
		userPosts = jQuery.parseJSON(userPosts);
		$(userPosts).each(function(){ 
			$("#postId").append("<option value='"+this.postId+"'>"+this.postName+"</option>");
		}); 
	}
	
}

//初始化可编辑节点信息
function initEditNodeInfo(data) {
	var editNodeInfo = data.editNodeInfo;
	editNodeInfo = jQuery.parseJSON(editNodeInfo);
	if(editNodeInfo.isEditNode){
		var hidden_info = "";
		hidden_info += '<input type="hidden" name="editNodeIds" id="editNodeIds"> ';
		hidden_info += '<input type="hidden" name="userIds" id="userIds"> ';
		$("#editNode-admin-tr").append(hidden_info);
		$("#editNode-admin-tr").css("display","");
		$("#editNodeAdminOptJsp").attr("src",PATH+"/bpm/bpmsap/editNodeAdmin/"+data.defId+"/"+editNodeInfo.nodeId);
	}
}

function initWorkFlowInfo(data){
	var workflowinfo = data.workflowinfo;
	if(workflowinfo){
		workflowinfo = jQuery.parseJSON(workflowinfo);
		if(workflowinfo.extUser){
			$("#extUser_td").html("<span>"+workflowinfo.extUser+"</span>");
		}
		if(workflowinfo.nodeDefName){
			$("#nodeDefName_td").html("<span>"+workflowinfo.nodeDefName+"</span>");
		}
		if(workflowinfo.outcomeNodes){
			$("#outcomeNodes_td").html("<span>"+workflowinfo.outcomeNodes+"</span>");
		}
	}
}


function error(data){
	
}
